<template>
  <el-config-provider :locale="messages[locale]" :size="config.size" :zIndex="config.zIndex" :button="config.button">
    <router-view></router-view>
  </el-config-provider>
</template>
<script setup>
import { RouterView } from "vue-router";
import { useI18n } from "vue-i18n";
import DisableDevtool from "disable-devtool";
import colorTool from "@/utils/color";
import { useConfigStore } from "@/store/modules/config";
import { siteConfigApi } from "@/api/modules/site";

const isAllowDebug = import.meta.env.VITE_BAN_DEBUG;
const { locale, messages } = useI18n();
const configStore = useConfigStore();

/**
 * @description: 响应式数据
 */
const config = ref({
  size: "default",
  zIndex: 2000,
  button: {
    autoInsertSpace: false,
  },
});

/**
 * @description: 设置系统配置
 * @return {*}
 */
const setSiteConfigApi = async () => {
  // const siteConfigData = await siteConfigApi();
  // 设置标题
  // configStore.siteTitle = siteConfigData.data.site_title;
  // 设置基础地址
  // configStore.siteUrl = siteConfigData.data.site_url;
};

/**
 * @description: 页面挂载后
 * @return {*}
 */
onMounted(() => {
  // 设置主题颜色
  const app_color = configStore.color;
  if (app_color) {
    document.documentElement.style.setProperty("--el-color-primary", app_color);
    for (let i = 1; i <= 9; i++) {
      document.documentElement.style.setProperty(`--el-color-primary-light-${i}`, colorTool.lighten(app_color, i / 10));
    }
    for (let i = 1; i <= 9; i++) {
      document.documentElement.style.setProperty(`--el-color-primary-dark-${i}`, colorTool.darken(app_color, i / 10));
    }
  }

  // 设置暗黑模式
  document.documentElement.classList[configStore.isDark ? "add" : "remove"]("dark");

  // 设置灰色模式
  if (configStore.isGrayscale) {
    document.body.setAttribute("style", `filter: grayscale(1);`);
  }

  // 设置色弱模式
  if (configStore.isInvert) {
    document.body.setAttribute("style", `filter: invert(80%);`);
  }

  // 是否禁止调试
  if (isAllowDebug == "true") {
    DisableDevtool({
      url: "about:blank",
      timeOutUrl: "about:blank",
      disableMenu: false,
    });
  }

  // 初始化系统配置
  setSiteConfigApi();
});
</script>
